Skip to content

doc: escape angle brackets in generated markdown#2395

Open
lawrence3699 wants to merge 1 commit intospf13:mainfrom
lawrence3699:fix/escape-markdown-angle-brackets
Open

doc: escape angle brackets in generated markdown#2395
lawrence3699 wants to merge 1 commit intospf13:mainfrom
lawrence3699:fix/escape-markdown-angle-brackets

Conversation

@lawrence3699
Copy link
Copy Markdown

Fixes #2375.

Angle-bracket placeholders in Short, Long, and SEE ALSO descriptions are currently emitted as raw markdown text, so generated docs like <output_path> are parsed as tags by MDX consumers.

This escapes those angle brackets in markdown prose while leaving the fenced UseLine() output unchanged, and adds a regression test for both the synopsis text and the SEE ALSO descriptions.

Validation:

  • go test ./doc
  • go test ./...
  • fresh temp-module repro that generated markdown and compiled it with @mdx-js/mdx

Copilot AI review requested due to automatic review settings April 22, 2026 01:35
@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@github-actions github-actions Bot added the area/docs-generation Generation of docs via Cobra label Apr 22, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes MDX compilation failures in generated Markdown docs by escaping angle-bracket placeholders in prose fields (Short, Long, and SEE ALSO descriptions), while leaving the fenced UseLine() synopsis unchanged.

Changes:

  • Escape angle brackets when emitting cmd.Short and cmd.Long into Markdown prose.
  • Escape angle brackets in SEE ALSO list descriptions (parent/child Short).
  • Add a regression test covering escaped prose and unescaped fenced UseLine() output.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
doc/md_docs.go Escapes angle brackets in Markdown prose output for synopsis/see-also descriptions.
doc/md_docs_test.go Adds regression test asserting escaped prose and unchanged fenced UseLine() output.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread doc/md_docs.go
}

func escapeAngleBrackets(s string) string {
return strings.NewReplacer("<", "\\<", ">", "\\>").Replace(s)
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

escapeAngleBrackets currently escapes both < and >. Escaping > is not needed to prevent MDX JSX parsing (escaping < is sufficient) and it will also change intended Markdown semantics, e.g. a description line starting with > will no longer render as a blockquote. Consider only escaping < (and update the new test expectations accordingly) to minimize formatting regressions.

Suggested change
return strings.NewReplacer("<", "\\<", ">", "\\>").Replace(s)
return strings.NewReplacer("<", "\\<").Replace(s)

Copilot uses AI. Check for mistakes.
Comment thread doc/md_docs.go
Comment on lines +119 to +121
func escapeAngleBrackets(s string) string {
return strings.NewReplacer("<", "\\<", ">", "\\>").Replace(s)
}
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

escapeAngleBrackets creates a new strings.Replacer on every call. Since GenMarkdownCustom may run across many commands (e.g., GenMarkdownTreeCustom), consider caching the replacer as a package-level var and reusing it to avoid repeated allocations/work.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/docs-generation Generation of docs via Cobra

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error: MDX compilation failed -- Expected a closing tag

3 participants